package com.woniuxy.medicine.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.entity.Medicine;
import com.woniuxy.commons.entity.QueryEntity;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.medicine.service.MedicineService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 雷珉
 * @date 2022年06月08日 16:41
 */
@RestController
@RequestMapping("/medicine/medicine")
public class MedicineController {
    @Resource
    private MedicineService MedicineService;

    @GetMapping("/")
    public ResponseResult<List<Medicine>> findAll(){
        return MedicineService.findAll();
    }

    @PostMapping("/condition")
    public ResponseResult<PageInfo<Medicine>> findAllByCondition(@RequestBody QueryEntity<Medicine> queryEntity){
        return MedicineService.findAllByCondition(queryEntity);
    }

    @GetMapping("/{id}")
    public ResponseResult<Medicine> findOne(@PathVariable("id") int id){
        return MedicineService.findOne(id);
    }

    @PostMapping("/batchFind")
    public ResponseResult<List<Medicine>> findBatch(@RequestBody int[] ids){
        return MedicineService.findBatch(ids);
    }

    @PostMapping("/")
    public ResponseResult addOne(@RequestBody Medicine Medicine){
        return MedicineService.addOne(Medicine);
    }

    @PutMapping("/")
    public ResponseResult updateOne(@RequestBody Medicine Medicine){
        return MedicineService.updateOne(Medicine);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteOne(@PathVariable("id") int id){
        return MedicineService.deleteOne(id);
    }

    @PostMapping("/batchDel")
    public ResponseResult deleteBatch(@RequestBody int[] ids){
        return MedicineService.deleteBatch(ids);
    }
}

